<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/9/23
  Time: 14:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="<c:url value='/js/jquery-1.8.2.js'/>"></script>
</head>
<body>
    <center>
        <form action="<c:url value='/newsServlet?method=list'/>" method="post">
            <input type="hidden" name="yema"/>
            新闻标题:<input type="text" name="title" value="${title}"/><input type="submit" value="查询"/>
        </form>
        <table border="1" rules="all">
            <tr align="center">
                <td colspan="100">
                    <font size="30">新闻列表</font>
                </td>
            </tr>
            <tr align="center" bgcolor="#CCCCFE">
                <th>
                    新闻编号
                </th>
                <th>
                    新闻标题
                </th>
                <th>
                    新闻摘要
                </th>
                <th>
                    作者
                </th>
                <th>
                    创建时间
                </th>
                <th>
                    操作
                </th>
            </tr>
            <c:forEach items="${list}" var="n" varStatus="aa">
                <tr bgcolor="${aa.index%2==0?'#89D0FE':''}">
                    <td>
                        ${n.id}
                    </td>
                    <td>
                            ${n.title}
                    </td>
                    <td>
                            ${n.summary}
                    </td>
                    <td>
                            ${n.author}
                    </td>
                    <td>
                            ${n.createdate}
                    </td>
                    <td>
                        <a href="<c:url value='/newsServlet?method=lookcomment&newsid=${n.id}'/>">查看评论</a>
                        <a href="<c:url value='/newsServlet?method=toadd&newsid=${n.id}'/>">评论</a>
                        <a href="#" onclick="deletenews(${n.id})">删除</a>
                    </td>
                </tr>
            </c:forEach>
            <tr align="center">
                <td colspan="100">
                    <a href="#" onclick="paging(1)">首页</a>&nbsp;&nbsp;
                    <a href="#" onclick="paging(${page.previousPage})">上一页</a>&nbsp;&nbsp;
                    <a href="#" onclick="paging(${page.nextPage})">下一页</a>&nbsp;&nbsp;
                    <a href="#" onclick="paging(${page.pageCount})">末页</a>&nbsp;&nbsp;
                    第${page.currentPage}页/共${page.pageCount}页
                </td>
            </tr>
        </table>
        <span id="xianshi" style="color: red"></span>
    </center>
</body>
<script>
    function paging(yema) {
        document.getElementsByName("yema")[0].value=yema;
        document.forms[0].submit();
    }
    function deletenews(newsid) {
        if(confirm("确定删除该新闻及其所有评论吗?")){
            $.post(
                "<c:url value='/newsServlet?method=delete'/>",
                {"newsid":newsid},
                function (data) {
                    $("#xianshi").html(data);
                    setTimeout(function () {
                        $("#xianshi").html("");
                        //location.reload();
                        location.href="<c:url value='/newsServlet?method=list'/>";
                    },3000)
                }
            );
        }
    }
</script>
</html>
